<?php


namespace App\Services;

use App\Models\MemberOther;
use App\Models\Order;
use App\Models\Config;
use App\Models\OrderLease;

class OrderService
{
    const ORDER_STATUS_CENCEL = 1;//订单关闭
    const ORDER_STATUS_NOT_PAY = 2;//待付款
    const ORDER_STATUS_SIGN_NOTPAY = 3;//签约待支付
    const ORDER_STATUS_SIGN_NOCHECK = 4;//待审核
    const ORDER_STATUS_SIGN_NOTRISK = 9;//待风控
    const ORDER_STATUS_PAY_SUCCESS = 10;//待发货
    const ORDER_STATUS_APPLY_REFUND = 11;//申请退款
    const ORDER_STATUS_APPLY_REFUND_SHOP_PASS = 12;//申请退款商家同意
    const ORDER_STATUS_APPLY_REFUND_SHOP_REFUSE = 13;//申请退款商家拒绝
    const ORDER_STATUS_APPLY_REFUND_ADMIN_REFUSE = 14;//申请退款平台拒绝
    const ORDER_STATUS_PART_REFUND = 15;//部分退款-已解约
    const ORDER_STATUS_REFUND_SUCCESS = 16;//退款成功
    const ORDER_STATUS_DELIVER_SUCCESS = 20;//已发货
    const ORDER_STATUS_CONFIRM_GOODS = 30;//确认收货-租用中
    const ORDER_STATUS_REFUND_NOCHECK = 31;//退货退款平台待审核
    const ORDER_STATUS_REFUND_NOSENT = 32;//退货退款用户待发货
    const ORDER_STATUS_REFUND_TOSENT = 33;//退货退款用户已发货
    const ORDER_STATUS_REFUND_CONFIRM = 34;//退货退款商家确认收货
    const ORDER_STATUS_REPAYMENT = 38;//还款中
    const ORDER_STATUS_OVERDUE = 39;//已逾期
    const ORDER_STATUS_TOBE_RETURNED = 40;//待归还
    const ORDER_STATUS_RETURN_APPLICATION = 41;//申请归还
    const ORDER_STATUS_RETURN_APP_AGREE = 42;//申请归还同意
    const ORDER_STATUS_RETURN_APP_REFUSE = 43;//申请归还拒绝
    const ORDER_STATUS_RETURN_DELIVER_SUCCESS = 44;//用户已发货
    const ORDER_STATUS_RETURN_CONFIRM_GOODS = 45;//商家确认收货
    const ORDER_STATUS_RETURN_OVERDUE = 49;//归还逾期
    const ORDER_STATUS_RENEWAL_APPLICATION = 50;//续租申请
    const ORDER_STATUS_RENEWAL_APP_AGREE = 51;//续租申请同意
    const ORDER_STATUS_RENEWAL_APP_REFUSE = 52;//续租申请拒绝
    const ORDER_STATUS_BUYOUT_APPLICATION = 56;//买断申请
    const ORDER_STATUS_BUYOUT_AGREE = 57;//买断申请同意
    const ORDER_STATUS_BUYOUT_REFUSE = 58;//买断申请拒绝
    const ORDER_STATUS_COMPLETED = 60;//交易完成
    const ORDER_STATUS_RENEWAL_APP_PAY_SUCCESS = 61;//续租已完成
    const ORDER_STATUS_BUYOUT_PAY = 62;//买断完成
    const ORDER_STATUS_ADVANCE_RETURN_FINISH = 63;//提前归还交易完成
    const ORDER_STATUS_REFUND_FINISH = 64;//退货退款完成
    const ORDER_STATUS_RETURN_FINISH = 65;//归还完成

    const ORDER_STATUS_NAME_LIST = [
        1 =>'订单关闭',
        2 =>'未人脸实名',
//        3 =>'签约待审核',
        3 =>'签约待支付',
        4 =>'待审核',
        9 =>'待风控',
        10 =>'待发货',
        11 =>'申请退款',
        12 =>'申请退款商家同意',
        13 =>'申请退款商家拒绝',
        14 =>'申请退款平台拒绝',
        15 =>'已解约',
        16 =>'退款成功',
        20 =>'已发货',
        30 =>'还款中',
        31 =>'退货退款平台待审核',
        32 =>'退货退款用户待发货',
        33 =>'退货退款用户已发货',
        34 =>'退货退款商家确认收货',
        38 =>'七天内未还',
        39 =>'已逾期',
        40 =>'待归还',
        41 =>'申请归还',
        42 =>'申请归还同意',
        43 =>'申请归还拒绝',
        44 =>'归还用户已发货',
        45 =>'归还商家确认收货',
        49 =>'归还逾期',
        50 =>'续租申请',
        51 =>'续租申请同意',
        52 =>'续租申请拒绝',
        56 =>'买断申请',
        57 =>'买断申请同意',
        58 =>'买断申请拒绝',
        60 =>'交易完成',
        61 =>'续租已完成',
        62 =>'买断完成',
        63 =>'提前归还交易完成',
        64 =>'退货退款完成',
        65 =>'归还完成',
    ];

    const SYNC_STATUS_NOSYNC = 1;//待同步
    const SYNC_STATUS_SYNC_SUCCESS = 2;//同步成功
    const SYNC_STATUS_SYNC_FALI = 3;//同步失败
    const SYNC_STATUS_CHECK_REFUNSE = 4;//报单审核拒绝
    const SYNC_STATUS_CHECK_PASS = 5;//报单审核通过

    const SYNC_STATUS_NAME_LIST = [
        1 =>'待同步',
        2 =>'同步成功',
        3 =>'同步失败',
    ];

    //租期
    const ORDER_MONTH_LIST = [
        '3'=>'3期',
        '6'=>'6期',
        '9'=>'9期',
        '12'=>'12期',
    ];

    const ORDER_LEASE_DAY_LIST = [
        '0'=>'默认按月',
//        '7'=>'7天',
        '15'=>'15天',
    ];

    //花呗订单结算状态
    const HUABEI_ORDER_SETTLE_STATUS_NO = 1;//未结算
    const HUABEI_ORDER_SETTLE_STATUS_YES = 2;//已结算
    const HUABEI_ORDER_SETTLE_STATUS_REFUSE = 3;//拒绝结算

    //获取订单类型
    public static function getOrderTypeName($order_status){
        if($order_status == OrderService::ORDER_STATUS_BUYOUT_PAY){//买断
            return '买断订单';
        }elseif($order_status == OrderService::ORDER_STATUS_RENEWAL_APP_PAY_SUCCESS){//续租
            return '续租订单';
        }else{
            return '普通订单';
        }
    }

     //风控查看人身份
    const RISK_USER_TYPE_ADMIN = 1;//管理员
    const RISK_USER_TYPE_SUPPLIER = 2;//商户

    const ORDER_LIST_STATUS_ALL = 'all'; //全部订单
    const ORDER_LIST_STATUS_SUCCESS_ALL = 'success_all'; //全部成功订单
    const ORDER_LIST_STATUS_NOT_CHECK = 'notCheck'; //待审核订单
    const ORDER_LIST_STATUS_NOT_PAY = 'notPay'; //待付款订单
    const ORDER_LIST_STATUS_NOT_RISK = 'notRisk'; //待风控订单
    const ORDER_LIST_STATUS_DELIVERED_NOT = 'deliveredNot'; //待发货订单
    const ORDER_LIST_STATUS_DELIVERED_IS = 'deliveredIs'; //已发货订单
    const ORDER_LIST_STATUS_ING = 'orderIng'; //租用中订单
    const ORDER_LIST_STATUS_COMPLETED = 'orderCompleted'; //交易完成订单
    const ORDER_LIST_STATUS_CANCEL = 'orderCancel'; //取消订单
    const ORDER_LIST_STATUS_RETURN = 'orderReturn'; //归还订单
    const ORDER_LIST_STATUS_BUY_OUT = 'orderBuyout'; //买断订单
    const ORDER_LIST_STATUS_RENEWAL = 'orderRenewal'; //续租订单
    const ORDER_LIST_STATUS_REFUND = 'orderRefund'; //退款订单
    /**
     * 非订单列表 使用 -notList后缀 区分开
     */
    const ORDER_WITHHOLD_OR_PAY = 'withholdOrPay-notList';//自动代扣和主动支付 订单状态
    const ORDER_MANUAL_WITHHOLD_OR_PAY = 'manualWithholdOrPay-notList';//手动代扣 订单状态
    const ORDER_OVERDUE_COUNT = 'orderOverdueCount-notList';//计算逾期 订单状态
    const ORDER_SETTLE_STATUS = 'orderSettle-notList';//花呗结算 订单状态

    const ORDER_SETTLE_CONFIRM_STATUS = 'orderSettle-confirm-List';//订单结算

    const ORDER_BUYOUT_STATUS = 'orderBuyout-notList';//买断订单状态
    const ORDER_REFUND_STATUS = 'orderRefund-notList';//退款订单状态
    const ORDER_FINISH_STATUS = 'orderFinish-notList';//订单已完结状态 智能合同使用
    const ORDER_REFUND_CHECK_STATUS = 'orderRefundCheck-notList';//退款审核订单状态
    const ORDER_FINISH_OPERATION_STATUS = 'orderOperationFinishStatus-notList';//完结按钮操作权限状态
    const OTHER_ORDER_REFUND_STATUS = 'dockingOrderRefund-notList';//对外接口退款审核订单状态
    const OTHER_ORDER_RENEWAL_STATUS = 'orderRenewalStatus-notList';//续租订单状态
    const ZLB_ORDER_STATUS = 'zlbOrderStatus-notList';//租赁宝上链订单状态


    /**
     * 订单状态
     * @param $type
     * @return array|bool
     */
    public static function getOrderStatus($type='',$is_source=false){
        $status = [
            'all'=>[
                self::ORDER_STATUS_CENCEL,//订单关闭
                self::ORDER_STATUS_NOT_PAY,//待付款
                self::ORDER_STATUS_SIGN_NOCHECK,//待审核
                self::ORDER_STATUS_SIGN_NOTPAY,//签约待支付
                self::ORDER_STATUS_SIGN_NOTRISK,//待风控
                self::ORDER_STATUS_PAY_SUCCESS,//待发货
                self::ORDER_STATUS_APPLY_REFUND,//申请退款
                self::ORDER_STATUS_APPLY_REFUND_SHOP_PASS,//申请退款商家同意
                self::ORDER_STATUS_APPLY_REFUND_SHOP_REFUSE,//申请退款商家拒绝
                self::ORDER_STATUS_APPLY_REFUND_ADMIN_REFUSE,//申请退款平台拒绝
                self::ORDER_STATUS_PART_REFUND,//部分退款
                self::ORDER_STATUS_REFUND_SUCCESS,//退款成功
                self::ORDER_STATUS_DELIVER_SUCCESS,//已发货
                self::ORDER_STATUS_CONFIRM_GOODS,//确认收货-租用中
                self::ORDER_STATUS_REFUND_NOCHECK,//退货退款平台待审核
                self::ORDER_STATUS_REFUND_NOSENT,//退货退款用户待发货
                self::ORDER_STATUS_REFUND_TOSENT,//退货退款用户已发货
                self::ORDER_STATUS_REFUND_CONFIRM,//退货退款商家确认收货
                self::ORDER_STATUS_REPAYMENT,//还款中
                self::ORDER_STATUS_OVERDUE,//已逾期
                self::ORDER_STATUS_TOBE_RETURNED,//待归还
                self::ORDER_STATUS_RETURN_APPLICATION,//申请归还
                self::ORDER_STATUS_RETURN_APP_AGREE,//申请归还同意
                self::ORDER_STATUS_RETURN_APP_REFUSE,//申请归还拒绝
                self::ORDER_STATUS_RETURN_DELIVER_SUCCESS,//用户已发货
                self::ORDER_STATUS_RETURN_CONFIRM_GOODS,//商家确认收货
                self::ORDER_STATUS_RETURN_OVERDUE,//归还逾期
                self::ORDER_STATUS_RENEWAL_APPLICATION,//续租申请
                self::ORDER_STATUS_RENEWAL_APP_AGREE,//续租申请同意
                self::ORDER_STATUS_RENEWAL_APP_REFUSE,//续租申请拒绝
                self::ORDER_STATUS_COMPLETED,//交易完成
                self::ORDER_STATUS_RENEWAL_APP_PAY_SUCCESS,//续租已完成
                self::ORDER_STATUS_BUYOUT_PAY,//买断完成
                self::ORDER_STATUS_ADVANCE_RETURN_FINISH,//提前归还交易完成
                self::ORDER_STATUS_REFUND_FINISH,//退货退款完成
                self::ORDER_STATUS_RETURN_FINISH,//归还完成
            ],
            'success_all'=>[
                self::ORDER_STATUS_SIGN_NOTRISK,//待风控
                self::ORDER_STATUS_PAY_SUCCESS,//待发货
                self::ORDER_STATUS_APPLY_REFUND,//申请退款
                self::ORDER_STATUS_APPLY_REFUND_SHOP_PASS,//申请退款商家同意
                self::ORDER_STATUS_APPLY_REFUND_SHOP_REFUSE,//申请退款商家拒绝
                self::ORDER_STATUS_APPLY_REFUND_ADMIN_REFUSE,//申请退款平台拒绝
                self::ORDER_STATUS_PART_REFUND,//部分退款
                self::ORDER_STATUS_REFUND_SUCCESS,//退款成功
                self::ORDER_STATUS_DELIVER_SUCCESS,//已发货
                self::ORDER_STATUS_CONFIRM_GOODS,//确认收货-租用中
                self::ORDER_STATUS_REFUND_NOCHECK,//退货退款平台待审核
                self::ORDER_STATUS_REFUND_NOSENT,//退货退款用户待发货
                self::ORDER_STATUS_REFUND_TOSENT,//退货退款用户已发货
                self::ORDER_STATUS_REFUND_CONFIRM,//退货退款商家确认收货
                self::ORDER_STATUS_REPAYMENT,//还款中
                self::ORDER_STATUS_OVERDUE,//已逾期
                self::ORDER_STATUS_TOBE_RETURNED,//待归还
                self::ORDER_STATUS_RETURN_APPLICATION,//申请归还
                self::ORDER_STATUS_RETURN_APP_AGREE,//申请归还同意
                self::ORDER_STATUS_RETURN_APP_REFUSE,//申请归还拒绝
                self::ORDER_STATUS_RETURN_DELIVER_SUCCESS,//用户已发货
                self::ORDER_STATUS_RETURN_CONFIRM_GOODS,//商家确认收货
                self::ORDER_STATUS_RETURN_OVERDUE,//归还逾期
                self::ORDER_STATUS_RENEWAL_APPLICATION,//续租申请
                self::ORDER_STATUS_RENEWAL_APP_AGREE,//续租申请同意
                self::ORDER_STATUS_RENEWAL_APP_REFUSE,//续租申请拒绝
                self::ORDER_STATUS_COMPLETED,//交易完成
                self::ORDER_STATUS_RENEWAL_APP_PAY_SUCCESS,//续租已完成
                self::ORDER_STATUS_BUYOUT_PAY,//买断完成
                self::ORDER_STATUS_ADVANCE_RETURN_FINISH,//提前归还交易完成
                self::ORDER_STATUS_REFUND_FINISH,//退货退款完成
                self::ORDER_STATUS_RETURN_FINISH,//归还完成
            ],
            'notCheck'=>[
                self::ORDER_STATUS_SIGN_NOCHECK,//待审核
            ],
            'notPay'=>[
                // self::ORDER_STATUS_NOT_PAY,//待付款
                self::ORDER_STATUS_SIGN_NOTPAY,//签约待支付
            ],
            'notRisk'=>[
                self::ORDER_STATUS_SIGN_NOTRISK,//待风控
            ],
            'deliveredNot'=>[
                self::ORDER_STATUS_PAY_SUCCESS,//待发货
            ],
            'deliveredIs'=>[
                self::ORDER_STATUS_DELIVER_SUCCESS,//已发货
            ],
            'orderIng'=>[
                self::ORDER_STATUS_CONFIRM_GOODS,//确认收货-租用中
                self::ORDER_STATUS_REPAYMENT,//还款中
                self::ORDER_STATUS_OVERDUE,//已逾期
            ],
            'orderCompleted'=>[
                self::ORDER_STATUS_COMPLETED,//交易完成
            ],
            'orderCancel'=>[
                self::ORDER_STATUS_CENCEL,//订单关闭
            ],
            'orderReturn'=>[
                self::ORDER_STATUS_TOBE_RETURNED,//待归还
                self::ORDER_STATUS_RETURN_APPLICATION,//申请归还
                self::ORDER_STATUS_RETURN_APP_AGREE,//申请归还同意
                self::ORDER_STATUS_RETURN_APP_REFUSE,//申请归还拒绝
                self::ORDER_STATUS_RETURN_DELIVER_SUCCESS,//用户已发货
                self::ORDER_STATUS_RETURN_CONFIRM_GOODS,//商家确认收货
                self::ORDER_STATUS_ADVANCE_RETURN_FINISH,//提前归还交易完成
                self::ORDER_STATUS_RETURN_FINISH,//归还完成
                self::ORDER_STATUS_RETURN_OVERDUE,//归还逾期
            ],
            'orderBuyout'=>[
                self::ORDER_STATUS_BUYOUT_PAY,//买断完成
            ],
            'orderRenewal'=>[
                self::ORDER_STATUS_RENEWAL_APPLICATION,//续租申请
                self::ORDER_STATUS_RENEWAL_APP_AGREE,//续租申请同意
                self::ORDER_STATUS_RENEWAL_APP_REFUSE,//续租申请拒绝
                self::ORDER_STATUS_RENEWAL_APP_PAY_SUCCESS,//续租已完成
            ],
            'orderRefund'=>[
                self::ORDER_STATUS_APPLY_REFUND,//申请退款
                self::ORDER_STATUS_APPLY_REFUND_SHOP_PASS,//申请退款商家同意
                self::ORDER_STATUS_APPLY_REFUND_SHOP_REFUSE,//申请退款商家拒绝
                self::ORDER_STATUS_APPLY_REFUND_ADMIN_REFUSE,//申请退款平台拒绝
                self::ORDER_STATUS_PART_REFUND,//部分退款
                self::ORDER_STATUS_REFUND_SUCCESS,//退款成功
                self::ORDER_STATUS_REFUND_NOCHECK,//退货退款平台待审核
                self::ORDER_STATUS_REFUND_NOSENT,//退货退款用户待发货
                self::ORDER_STATUS_REFUND_TOSENT,//退货退款用户已发货
                self::ORDER_STATUS_REFUND_CONFIRM,//退货退款商家确认收货
                self::ORDER_STATUS_REFUND_FINISH,//退货退款完成
            ],
            'withholdOrPay-notList'=>[
                self::ORDER_STATUS_SIGN_NOTPAY,//签约待支付
                self::ORDER_STATUS_SIGN_NOTRISK,//待风控
                self::ORDER_STATUS_PAY_SUCCESS,//待发货
                self::ORDER_STATUS_DELIVER_SUCCESS,//已发货
                self::ORDER_STATUS_CONFIRM_GOODS,////确认收货-租用中
                self::ORDER_STATUS_REPAYMENT,//还款中
                self::ORDER_STATUS_OVERDUE,//已逾期
                self::ORDER_STATUS_APPLY_REFUND,//申请退款
                self::ORDER_STATUS_APPLY_REFUND_SHOP_PASS,//申请退款商家同意
                self::ORDER_STATUS_APPLY_REFUND_SHOP_REFUSE,//申请退款商家拒绝
                self::ORDER_STATUS_APPLY_REFUND_ADMIN_REFUSE,//申请退款平台拒绝
                self::ORDER_STATUS_REFUND_NOCHECK,//退货退款平台待审核
                self::ORDER_STATUS_OVERDUE,//已逾期
                self::ORDER_STATUS_TOBE_RETURNED,//待归还
                self::ORDER_STATUS_RETURN_APPLICATION,//申请归还
                self::ORDER_STATUS_RETURN_APP_REFUSE,//申请归还拒绝
                self::ORDER_STATUS_RENEWAL_APPLICATION,//续租申请
                self::ORDER_STATUS_RENEWAL_APP_REFUSE,//续租申请拒绝
            ],
            'orderOverdueCount-notList'=>[
                self::ORDER_STATUS_PAY_SUCCESS,//待发货
                self::ORDER_STATUS_DELIVER_SUCCESS,//已发货
                self::ORDER_STATUS_CONFIRM_GOODS,//确认收货-租用中
                self::ORDER_STATUS_REPAYMENT,//还款中
                self::ORDER_STATUS_OVERDUE,//已逾期
                self::ORDER_STATUS_APPLY_REFUND,//申请退款
                self::ORDER_STATUS_APPLY_REFUND_SHOP_REFUSE,//申请退款商家拒绝
                self::ORDER_STATUS_APPLY_REFUND_ADMIN_REFUSE,//申请退款平台拒绝
                self::ORDER_STATUS_RETURN_APPLICATION,//申请归还
                self::ORDER_STATUS_RETURN_APP_REFUSE,//申请归还拒绝
                self::ORDER_STATUS_RENEWAL_APPLICATION,//续租申请
                self::ORDER_STATUS_RENEWAL_APP_REFUSE,//续租申请拒绝
            ],
            'orderSettle-notList'=>[
                self::ORDER_STATUS_PAY_SUCCESS,//待发货
                self::ORDER_STATUS_DELIVER_SUCCESS,//已发货
                self::ORDER_STATUS_CONFIRM_GOODS,//确认收货-租用中
                self::ORDER_STATUS_PART_REFUND,//部分退款
                self::ORDER_STATUS_REPAYMENT,//还款中
                self::ORDER_STATUS_OVERDUE,//已逾期
                self::ORDER_STATUS_TOBE_RETURNED,//待归还
                self::ORDER_STATUS_RETURN_APPLICATION,//申请归还
                self::ORDER_STATUS_RETURN_APP_AGREE,//申请归还同意
                self::ORDER_STATUS_RETURN_APP_REFUSE,//申请归还拒绝
                self::ORDER_STATUS_RETURN_DELIVER_SUCCESS,//用户已发货
                self::ORDER_STATUS_RETURN_CONFIRM_GOODS,//商家确认收货
                self::ORDER_STATUS_RETURN_OVERDUE,//归还逾期
                self::ORDER_STATUS_RENEWAL_APPLICATION,//续租申请
                self::ORDER_STATUS_RENEWAL_APP_AGREE,//续租申请同意
                self::ORDER_STATUS_RENEWAL_APP_REFUSE,//续租申请拒绝
                self::ORDER_STATUS_COMPLETED,//交易完成
                self::ORDER_STATUS_RENEWAL_APP_PAY_SUCCESS,//续租已完成
                self::ORDER_STATUS_BUYOUT_PAY,//买断完成
                self::ORDER_STATUS_ADVANCE_RETURN_FINISH,//提前归还交易完成
                self::ORDER_STATUS_REFUND_FINISH,//退货退款完成
                self::ORDER_STATUS_RETURN_FINISH,//归还完成
            ],
            'orderSettle-confirm-List'=>[
//                self::ORDER_STATUS_DELIVER_SUCCESS,//已发货
                self::ORDER_STATUS_CONFIRM_GOODS,//确认收货-租用中
                self::ORDER_STATUS_REPAYMENT,//还款中
                self::ORDER_STATUS_OVERDUE,//已逾期
                self::ORDER_STATUS_TOBE_RETURNED,//待归还
                self::ORDER_STATUS_RETURN_APPLICATION,//申请归还
                self::ORDER_STATUS_RETURN_APP_AGREE,//申请归还同意
                self::ORDER_STATUS_RETURN_APP_REFUSE,//申请归还拒绝
                self::ORDER_STATUS_RETURN_DELIVER_SUCCESS,//用户已发货
                self::ORDER_STATUS_RETURN_CONFIRM_GOODS,//商家确认收货
                self::ORDER_STATUS_RETURN_OVERDUE,//归还逾期
                self::ORDER_STATUS_RENEWAL_APPLICATION,//续租申请
                self::ORDER_STATUS_RENEWAL_APP_AGREE,//续租申请同意
                self::ORDER_STATUS_RENEWAL_APP_REFUSE,//续租申请拒绝
                self::ORDER_STATUS_COMPLETED,//交易完成
                self::ORDER_STATUS_RENEWAL_APP_PAY_SUCCESS,//续租已完成
                self::ORDER_STATUS_BUYOUT_PAY,//买断完成
                self::ORDER_STATUS_ADVANCE_RETURN_FINISH,//提前归还交易完成
                self::ORDER_STATUS_RETURN_FINISH,//归还完成
            ],
            'orderBuyout-notList' => [
                self::ORDER_STATUS_SIGN_NOTRISK,//待风控
                self::ORDER_STATUS_PAY_SUCCESS,//待发货
                self::ORDER_STATUS_DELIVER_SUCCESS,//已发货
                self::ORDER_STATUS_CONFIRM_GOODS,//确认收货-租用中
                self::ORDER_STATUS_REPAYMENT,//还款中
                self::ORDER_STATUS_OVERDUE,//已逾期
                self::ORDER_STATUS_TOBE_RETURNED,//待归还
                self::ORDER_STATUS_RETURN_OVERDUE,//归还逾期
            ],
            'orderRefund-notList' => [
                self::ORDER_STATUS_APPLY_REFUND,//申请退款
                self::ORDER_STATUS_APPLY_REFUND_SHOP_PASS,//申请退款商家同意
                self::ORDER_STATUS_APPLY_REFUND_SHOP_REFUSE,//申请退款商家拒绝
                self::ORDER_STATUS_APPLY_REFUND_ADMIN_REFUSE,//申请退款平台拒绝
                self::ORDER_STATUS_PART_REFUND,//部分退款
                self::ORDER_STATUS_REFUND_SUCCESS,//退款成功
                self::ORDER_STATUS_REFUND_NOCHECK,//退货退款平台待审核
                self::ORDER_STATUS_REFUND_NOSENT,//退货退款用户待发货
                self::ORDER_STATUS_REFUND_TOSENT,//退货退款用户已发货
                self::ORDER_STATUS_REFUND_CONFIRM,//退货退款商家确认收货
                self::ORDER_STATUS_REFUND_FINISH,//退货退款完成
            ],
            'orderFinish-notList' => [
                self::ORDER_STATUS_PART_REFUND,//部分退款
                self::ORDER_STATUS_REFUND_SUCCESS,//退款成功
                self::ORDER_STATUS_REFUND_FINISH,//退货退款完成
                self::ORDER_STATUS_COMPLETED,//交易完成
                self::ORDER_STATUS_RENEWAL_APP_PAY_SUCCESS,//续租已完成
                self::ORDER_STATUS_BUYOUT_PAY,//买断完成
                self::ORDER_STATUS_ADVANCE_RETURN_FINISH,//提前归还交易完成
                self::ORDER_STATUS_REFUND_FINISH,//退货退款完成
                self::ORDER_STATUS_RETURN_FINISH,//归还完成
            ],
            'orderRefundCheck-notList' => [
                self::ORDER_STATUS_APPLY_REFUND,//申请退款
                self::ORDER_STATUS_APPLY_REFUND_SHOP_PASS,//申请退款商家同意
                self::ORDER_STATUS_APPLY_REFUND_SHOP_REFUSE,//申请退款商家拒绝
                self::ORDER_STATUS_APPLY_REFUND_ADMIN_REFUSE,//申请退款平台拒绝
            ],
            'dockingOrderRefund-notList' => [
                self::ORDER_STATUS_SIGN_NOCHECK,//待审核
                self::ORDER_STATUS_SIGN_NOTPAY,//签约待支付
                self::ORDER_STATUS_SIGN_NOTRISK,//待风控
                self::ORDER_STATUS_PAY_SUCCESS,//待发货
                self::ORDER_STATUS_APPLY_REFUND,//申请退款
                self::ORDER_STATUS_APPLY_REFUND_SHOP_PASS,//申请退款商家同意
                self::ORDER_STATUS_APPLY_REFUND_SHOP_REFUSE,//申请退款商家拒绝
                self::ORDER_STATUS_APPLY_REFUND_ADMIN_REFUSE,//申请退款平台拒绝
                self::ORDER_STATUS_DELIVER_SUCCESS,//已发货
                self::ORDER_STATUS_CONFIRM_GOODS,//确认收货-租用中
                self::ORDER_STATUS_REFUND_NOCHECK,//退货退款平台待审核
                self::ORDER_STATUS_REFUND_NOSENT,//退货退款用户待发货
                self::ORDER_STATUS_REFUND_TOSENT,//退货退款用户已发货
                self::ORDER_STATUS_REFUND_CONFIRM,//退货退款商家确认收货
                self::ORDER_STATUS_REPAYMENT,//还款中
                self::ORDER_STATUS_OVERDUE,//已逾期
                self::ORDER_STATUS_TOBE_RETURNED,//待归还
            ],
            'manualWithholdOrPay-notList' => [
                self::ORDER_STATUS_SIGN_NOCHECK,//待审核
                self::ORDER_STATUS_SIGN_NOTPAY,//签约待支付
                self::ORDER_STATUS_SIGN_NOTRISK,//待风控
                self::ORDER_STATUS_PAY_SUCCESS,//待发货
                self::ORDER_STATUS_APPLY_REFUND,//申请退款
                self::ORDER_STATUS_APPLY_REFUND_SHOP_PASS,//申请退款商家同意
                self::ORDER_STATUS_APPLY_REFUND_SHOP_REFUSE,//申请退款商家拒绝
                self::ORDER_STATUS_APPLY_REFUND_ADMIN_REFUSE,//申请退款平台拒绝
                self::ORDER_STATUS_DELIVER_SUCCESS,//已发货
                self::ORDER_STATUS_CONFIRM_GOODS,//确认收货-租用中
                self::ORDER_STATUS_REFUND_NOCHECK,//退货退款平台待审核
                self::ORDER_STATUS_REFUND_NOSENT,//退货退款用户待发货
                self::ORDER_STATUS_REFUND_TOSENT,//退货退款用户已发货
                self::ORDER_STATUS_REFUND_CONFIRM,//退货退款商家确认收货
                self::ORDER_STATUS_REPAYMENT,//还款中
                self::ORDER_STATUS_OVERDUE,//已逾期
                self::ORDER_STATUS_TOBE_RETURNED,//待归还
                self::ORDER_STATUS_RETURN_APPLICATION,//申请归还
                self::ORDER_STATUS_RETURN_APP_AGREE,//申请归还同意
                self::ORDER_STATUS_RETURN_APP_REFUSE,//申请归还拒绝
                self::ORDER_STATUS_RETURN_DELIVER_SUCCESS,//用户已发货
                self::ORDER_STATUS_RETURN_CONFIRM_GOODS,//商家确认收货
                self::ORDER_STATUS_RETURN_OVERDUE,//归还逾期
                self::ORDER_STATUS_RENEWAL_APPLICATION,//续租申请
                self::ORDER_STATUS_RENEWAL_APP_AGREE,//续租申请同意
                self::ORDER_STATUS_RENEWAL_APP_REFUSE,//续租申请拒绝
            ],
            'orderOperationFinishStatus-notList'=>[
                self::ORDER_STATUS_SIGN_NOTRISK,//待风控
                self::ORDER_STATUS_PAY_SUCCESS,//待发货
                self::ORDER_STATUS_APPLY_REFUND,//申请退款
                self::ORDER_STATUS_APPLY_REFUND_SHOP_PASS,//申请退款商家同意
                self::ORDER_STATUS_APPLY_REFUND_SHOP_REFUSE,//申请退款商家拒绝
                self::ORDER_STATUS_APPLY_REFUND_ADMIN_REFUSE,//申请退款平台拒绝
                self::ORDER_STATUS_DELIVER_SUCCESS,//已发货
                self::ORDER_STATUS_CONFIRM_GOODS,//确认收货-租用中
                self::ORDER_STATUS_REFUND_NOCHECK,//退货退款平台待审核
                self::ORDER_STATUS_REFUND_NOSENT,//退货退款用户待发货
                self::ORDER_STATUS_REFUND_TOSENT,//退货退款用户已发货
                self::ORDER_STATUS_REFUND_CONFIRM,//退货退款商家确认收货
                self::ORDER_STATUS_REPAYMENT,//还款中
                self::ORDER_STATUS_OVERDUE,//已逾期
                self::ORDER_STATUS_TOBE_RETURNED,//待归还
                self::ORDER_STATUS_RETURN_APPLICATION,//申请归还
                self::ORDER_STATUS_RETURN_APP_AGREE,//申请归还同意
                self::ORDER_STATUS_RETURN_APP_REFUSE,//申请归还拒绝
                self::ORDER_STATUS_RETURN_DELIVER_SUCCESS,//用户已发货
                self::ORDER_STATUS_RETURN_CONFIRM_GOODS,//商家确认收货
                self::ORDER_STATUS_RETURN_OVERDUE,//归还逾期
                self::ORDER_STATUS_RENEWAL_APPLICATION,//续租申请
                self::ORDER_STATUS_RENEWAL_APP_AGREE,//续租申请同意
                self::ORDER_STATUS_RENEWAL_APP_REFUSE,//续租申请拒绝
                self::ORDER_STATUS_BUYOUT_APPLICATION,//买断申请
                self::ORDER_STATUS_BUYOUT_AGREE,//买断申请同意
                self::ORDER_STATUS_BUYOUT_REFUSE,//买断申请拒绝
            ],
            'orderRenewalStatus-notList'=>[
                self::ORDER_STATUS_SIGN_NOCHECK,//待审核
                self::ORDER_STATUS_SIGN_NOTPAY,//签约待支付
                self::ORDER_STATUS_CONFIRM_GOODS,//确认收货-租用中
                self::ORDER_STATUS_REFUND_NOCHECK,//退货退款平台待审核
                self::ORDER_STATUS_REFUND_NOSENT,//退货退款用户待发货
                self::ORDER_STATUS_REFUND_TOSENT,//退货退款用户已发货
                self::ORDER_STATUS_REFUND_CONFIRM,//退货退款商家确认收货
                self::ORDER_STATUS_REPAYMENT,//还款中
                self::ORDER_STATUS_OVERDUE,//已逾期
                self::ORDER_STATUS_TOBE_RETURNED,//待归还
                self::ORDER_STATUS_RETURN_APPLICATION,//申请归还
                self::ORDER_STATUS_RETURN_APP_AGREE,//申请归还同意
                self::ORDER_STATUS_RETURN_APP_REFUSE,//申请归还拒绝
                self::ORDER_STATUS_RETURN_DELIVER_SUCCESS,//用户已发货
                self::ORDER_STATUS_RETURN_CONFIRM_GOODS,//商家确认收货
                self::ORDER_STATUS_RETURN_OVERDUE,//归还逾期
                self::ORDER_STATUS_RENEWAL_APPLICATION,//续租申请
                self::ORDER_STATUS_RENEWAL_APP_AGREE,//续租申请同意
                self::ORDER_STATUS_RENEWAL_APP_REFUSE,//续租申请拒绝
                self::ORDER_STATUS_COMPLETED,//交易完成
                self::ORDER_STATUS_RENEWAL_APP_PAY_SUCCESS,//续租已完成
                self::ORDER_STATUS_BUYOUT_PAY,//买断完成
                self::ORDER_STATUS_ADVANCE_RETURN_FINISH,//提前归还交易完成
                self::ORDER_STATUS_REFUND_FINISH,//退货退款完成
                self::ORDER_STATUS_RETURN_FINISH,//归还完成
            ],
        ];
        if($is_source){
            return $status;
        }
        return isset($status[$type]) ? $status[$type] : [];
    }

    //获取订单状态名称
    public static function getOrderStatusName($orderStatus){
        $list = self::ORDER_STATUS_NAME_LIST;
        return isset($list[$orderStatus]) ? $list[$orderStatus] : '';
    }

    //签署用户授权协议--第一个 pact_url_3
    static public function createOne($order){
        //创建个人账号
        if(empty($order['esign_user_id'])){
            $result = EsignService::addPersonAccountID($order['cert_no'],$order['cert_name'],$order['cert_no'],$order['user_mobile']);
            $data1 = $result['data'];
            if(!empty($data1['accountId'])){
                $esign_user_id = $data1['accountId'];
                MemberOther::where('id',$order['uid'])->update(['esign_user_id'=>$esign_user_id]);
            }else{
                return ReturnMsg(CommonService::HTTP_CODE_FAIL, '合同签署账号创建失败');
            }
        }else{
            $user_mobile = !empty($order['user_mobile'])?$order['user_mobile']:$order['mobile'];
            $esign_user_id = EsignService::updateAccounts($order['esign_user_id'],$user_mobile,$order['cert_name']);
        }

        //创建个人印章
        if(empty($order['esign_seal_id'])){
            // $seal_id = EsignService::personaltemplate($esign_user_id,$order['cert_name']);

            $seal_id = EsignService::personaltemplate($esign_user_id,$order['cert_name'].mt_rand(10,99));

            if($seal_id){
                MemberOther::where('id',$order['uid'])->update(['esign_seal_id'=>$seal_id]);
            }else{
                $flag = false;
            }
        }

        //下单成功发起征信静默授权
        $result = EsignService::createCreditAuth($order);
        // dd($result);
        if(isset($result['data']) && !empty($result['data']['flowId'])){
            $flow_id = $result['data']['flowId'];
            $order_sign['flow_id_3'] = $flow_id;

            $res = Order::where('id',$order['id'])->update($order_sign);

            return $res;
        }else{
            return '';
        }
    }

    //签署个人信用报告授权书--新征信--第一个pact_url_2
    static public function createTwo($order){
        $resa = Order::where('id',$order['id'])->value('pact_url_2');
        if($resa){
            return true;
        }
        if(empty($order['esign_user_id'])){
            $data1= EsignV3Service::addPersonAccountID($order['cert_name'],$order['cert_no']);
            if(!empty($data1['accountId'])){
                $esign_user_id = $data1['accountId'];
                $order['esign_user_id']=$esign_user_id;
                MemberOther::where(['id'=>$order['uid']])->update(['esign_user_id'=>$esign_user_id]);
            }else{
                return ReturnMsg(CommonService::HTTP_CODE_FAIL, '合同签署账号创建失败');
            }
        }else{
            $accountId= EsignV3Service::updateAccounts($order['esign_user_id'],$order['cert_no'],$order['cert_name']);
            if(!empty($accountId)){
                $esign_user_id = $accountId;
                $order['esign_user_id']=$esign_user_id;
                MemberOther::where('id',$order['uid'])->update(['esign_user_id'=>$esign_user_id]);
            }else{
                return ReturnMsg(CommonService::HTTP_CODE_FAIL, '合同签署账号创建失败');
            }
        }
        //下单成功发起征信静默授权
        $result = EsignV3Service::createIncestUserAuth($order);
        // dd($result);
        if(isset($result['data']) && !empty($result['data'])){
            //合同下载
            $flow_id = md5($result['data']);

            $fileName = $flow_id.".pdf";
            $path=$result['data'];
            $uploud_res = AlipayService::upload($fileName,$path);
            if($uploud_res['status']){
                if(file_exists($path)){
                    unlink($path);
                }
            }
            $order_sign['flow_id_2'] = $flow_id;
            $order_sign['pact_url_2'] = $flow_id.'.pdf';

            $res = Order::where('id',$order['id'])->update($order_sign);

//            }

            return $res;
        }else{
            return '失败';
        }
    }

    //签署个人授权书--新征信--第一个pact_url_3
    static public function createTwoOne($order){

        $resa = Order::where('id',$order['id'])->value('pact_url_3');
        if($resa){
            return true;
        }
        if(empty($order['esign_user_id'])){
            $data1= EsignV3Service::addPersonAccountID($order['cert_name'],$order['cert_no']);
            if(!empty($data1['accountId'])){
                $esign_user_id = $data1['accountId'];
                $order['esign_user_id']=$esign_user_id;
                MemberOther::where(['id'=>$order['uid']])->update(['esign_user_id'=>$esign_user_id]);
            }else{
                return ReturnMsg(CommonService::HTTP_CODE_FAIL, '合同签署账号创建失败');
            }
        }else{
            $accountId= EsignV3Service::updateAccounts($order['esign_user_id'],$order['cert_no'],$order['cert_name']);
            if(!empty($accountId)){
                $esign_user_id = $accountId;
                $order['esign_user_id']=$esign_user_id;
                MemberOther::where('id',$order['uid'])->update(['esign_user_id'=>$esign_user_id]);
            }else{
                return ReturnMsg(CommonService::HTTP_CODE_FAIL, '合同签署账号创建失败');
            }
        }
        //下单成功发起征信静默授权
        $result = EsignV3Service::createIncestUserAuthCall($order);
        if(isset($result['data']) && !empty($result['data'])){
            $flow_id = md5($result['data']);
            $fileName = $flow_id.".pdf";
            $path=$result['data'];
            $uploud_res = AlipayService::upload($fileName,$path);
            if($uploud_res['status']){
                if(file_exists($path)){
                    unlink($path);
                }
            }
            $order_sign['flow_id_3'] = $flow_id;
            $order_sign['pact_url_3'] = $flow_id.'.pdf';

            $res = Order::where('id',$order['id'])->update($order_sign);


            return $res;
        }else{
            return '失败';
        }
    }

    //签署融资租赁委托担保合同--第三个
    static public function createThree($order){
        //没有授权开始授权签约
        //创建企业账号
        $company = Config::where('type',CommonService::COMPANY_CREDIT)->get();
        $company = $company ? $company->toArray() : [];
        $company_arr = [];
        $company_arr['esign_user_id'] = $company[0]['value'];
        $company_arr['esign_seal_id'] = $company[1]['value'];

        if(empty($company_arr['esign_user_id'])){
                $orgid = EsignService::addTerraceAccountId(config('esign.COMPANYID'),'',config('esign.COMPANYNAME'),config('esign.COMPANYID'));

                if($orgid){
                    $res = Config::where('type',CommonService::COMPANY_CREDIT)->where('con','esign_user_id')->update(['value'=>$orgid]);

                }else{
                    $flag = false;
                }
        }else{
            $orgid = $company_arr['esign_user_id'];
        }

        //创建企业印章
        if(empty($company_arr['esign_seal_id'])){

            $seal_id = EsignService::addOrganizeSeals($orgid);

            if($seal_id){
                Config::where('type',CommonService::COMPANY_CREDIT)->where('con','esign_seal_id')->update(['value'=>$seal_id]);
            }else{
                $flag = false;
            }
        }else{
            $seal_id = '';
        }
        //下单成功发起征信融资租赁委托担保合同
        $result = EsignService::createCreditCompanyAuth($order,$orgid,$seal_id);
        // dd($result);
        if(isset($result['data']) && !empty($result['data']['flowId'])){
            $flow_id = $result['data']['flowId'];
            $order_sign['flow_id_4'] = $flow_id;

            $res = Order::where('id',$order['id'])->update($order_sign);
            return $res;
        }else{
            return '失败';
        }


    }

    //创建合同并获取签署地址
    static public function getSignUrl($order){
        if(empty($order['ant_user_id'])){
            $ant_user_data['user_name'] = $order['cert_name'];
            $ant_user_data['idcard'] = $order['cert_no'];
            $ant_user_data['user_mobile'] = $order['user_mobile'];
            $ant_user_data['user_id'] = 'T'.$order['x_user_id'];
            $ant_result = AntchainService::userCreate($ant_user_data);
            if($ant_result['status']){
                $ant_user_id = $ant_result['data'];
                MemberOther::where('id',$order['x_user_id'])->update(['ant_user_id'=>$ant_user_id]);
            }else{
                return ReturnMsg(CommonService::HTTP_CODE_FAIL, '合同创建失败，请联系客服解决1',$ant_result);
            }
        }else{
            $ant_user_id = $order['ant_user_id'];
        }
        if(!empty($ant_user_id)){
            $order['pact_type'] = GoodsService::getGoodsPactName($order['pact_type']);
            $order['isBuyout'] = $order['is_buy_out'];
            $order['is_buy_out'] = GoodsService::getGoodsBuyoutName($order['is_buy_out']);
            $fisrt_month_rent = OrderLease::where('order_id',$order['id'])->where("which_period",1)->value("rent");
            $month_rent = OrderLease::where('order_id',$order['id'])->where("which_period","2")->value("rent");
            //通过电子合同模板添加文档
            if(!strstr($order['address'],'省')&&!strstr($order['address'],'市')){
                $order['address']=$order['prov'].$order['city'].$order['area'].$order['address'];
            }
            $order_data = [
                'order_sn' => $order['trade_no'],
                'first_name' => $order['mechanism'],
                'first_address' => str_replace('-','',$order['company_area']).$order['company'],
                //'first_address' => $order['company_area'].$order['company'],
                'first_code' => $order['companyid'],
                'first_mobile' => $order['contact_tel'],
                'user_name' => $order['cert_name'],
                'user_address' => $order['address'],
                'user_idcard' => $order['cert_no'],
                'user_mobile' => $order['user_mobile'],
                'third_name' => '瑞安市诺明网络科技有限公司',
                'third_address' => '浙江省温州市瑞安市玉海街道解放中路118号（后半间）',
                'third_code' => '91330381MAC65FWH5X',
                'third_mobile' => '19357616167',
                'order_no' => $order['trade_no'],
                'user_data' => $order['cert_name'].'('.$order['cert_no'].')',
                'goods_name' => $order['goods_title'],
                'setmeal_name' => $order['setmeal_title'],
                'amount' => $order['amount'],
                // 'setmeal_foregift' => $order['setmeal_foregift'],
                'is_new' => $order['new_grade']<100?'否':'是',
                'meal' => $order['pact_type'],
                // 'goods_price' => $order['website_price'].'元',
                // 'total_rent' => sprintf("%.2f",$order['website_price']*$order['amount']).'元',
                'total_rent1' => $order['rent_total'].'元',
                // 'month_rent' => sprintf("%.2f",$order['rent_total']/$order['month_total']).'元',
                'first_month_rent'=>$fisrt_month_rent,
                'month_rent' => $month_rent.'元'.'（月租金=(总租金-首付金)/期数）',
                'lease_term' =>  date('Y.m.d',strtotime($order['begin_time'])).'-'.date('Y.m.d',strtotime($order['end_time'])),
                'pay_type' => '分期付租',
                'amount_pay' => $order['isBuyout']==1?$order['setmeal_foregift'].'元':$order['is_buy_out'],
                'buy_out_price' => '0.00元',
                'receiving_address' => $order['address'],
                'user_name1' => $order['cert_name'],
                'user_mobile1' => $order['user_mobile'],
                'user_address1' => $order['address'],
                'email'=>$order['user_email'],
                'first_name1' => $order['mechanism'],
                'first_mobile1' => $order['contact_tel'],
                'first_address1' => $order['company'],
                'first_name2' => $order['mechanism'],
                'user_name2' => $order['cert_name'],
                'third_name2' => '瑞安市诺明网络科技有限公司',
                'sign_year' => date("Y"),
                'sign_month' => date("m"),
                'sign_day' => date("d"),
                'insurance_price' => GoodsService::getGoodsInsurance($order['is_insurance_choose'],$order['is_insurance_choose_custom']).'元（与第一期租金一并支付）',
            ];
            // echo '<pre>';
            // print_r($order_data);
            // dd(1);
            $fali_result = AntchainService::fileAdd($order_data);
            // return $fali_result;
            //企业账号静默签署
            AntchainService::signAuth($order['mer_ant_id']);
            AntchainService::signAuth(config('antchain.TXZ_ID'));
            if($fali_result['status']) {
                $file_id = $fali_result['data'];
                if($file_id){
                    $flow_data['file_id'] = $file_id;
                    $flow_data['ant_user_id'] = $ant_user_id;
                    $pay_rules = OrderLease::getOrderLease($order);
                    // dd($flow_data);
                    $sign_flow_result = AntchainService::signflowCreate($flow_data,$pay_rules,$order['id']);
                    // echo 1;
                    // dd($sign_flow_result);
                    if($sign_flow_result['status']){
                        $flow_id = $sign_flow_result['data'];
                        $add_result = AntchainService::documentAdd($file_id,$flow_id);
                        if($add_result['status']){
                            $sign_data['flow_id'] = $flow_id;
                            $sign_data['file_id'] = $file_id;
                            $signfield_result = AntchainService::signfieldAdd($sign_data,$order['mer_ant_id']);
                            // return $signfield_result;
                            if($signfield_result['status']){
                                $sign_data['ant_user_id'] = $ant_user_id;
                                $hand_result = AntchainService::handsignfieldCreate($sign_data);
                                // dd($hand_result);
                                if($hand_result['status']){
                                    $start_result = AntchainService::flowStart($flow_id);
                                    if($start_result['status']){
                                        $signurl_data = AntchainService::getSignurl($ant_user_id,$flow_id);
                                        if($signurl_data['status']){
                                            $sign_url = $signurl_data['data']['url'];
                                            Order::where('id',$order['id'])->update(['flow_id'=>$flow_id,'sign_status'=>EsignService::ESIGN_STATUS_SIGNING,'sign_url'=>$sign_url]);
                                        }else{
                                            return ReturnMsg(CommonService::HTTP_CODE_FAIL, '合同获取签署地址失败，请联系客服解决',$signurl_data);
                                        }
                                    }else{
                                        return ReturnMsg(CommonService::HTTP_CODE_FAIL, '合同创建流程开启失败，请联系客服解决',$hand_result);
                                    }
                                }else{
                                    return ReturnMsg(CommonService::HTTP_CODE_FAIL, '合同创建添加签署区失败，请联系客服解决',$hand_result);
                                }
                            }else{
                                return ReturnMsg(CommonService::HTTP_CODE_FAIL, '合同创建添加自动盖章签署区失败，请联系客服解决',$signfield_result);
                            }
                        }else{
                            return ReturnMsg(CommonService::HTTP_CODE_FAIL, '合同创建添加待签署文档失败，请联系客服解决',$add_result);
                        }
                    }else{
                        return ReturnMsg(CommonService::HTTP_CODE_FAIL, '合同创建签署流程失败，请联系客服解决！',$sign_flow_result);
                    }
                }else{
                    return ReturnMsg(CommonService::HTTP_CODE_FAIL, '合同创建失败，请联系客服解决！！',$fali_result);
                }
            }else{
                return ReturnMsg(CommonService::HTTP_CODE_FAIL, '合同创建添加文档失败，请联系客服解决！！！',$fali_result);
            }
        }
    }









}
